#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAXN = 1000000;
vector<vector<int>> tree;
int a[MAXN + 5];

// 合并两个有序数组到 res
void mergeVectors(const vector<int>& A, const vector<int>& B, vector<int>& res) {
    res.resize(A.size() + B.size());
    int i = 0, j = 0, k = 0;
    while (i < (int)A.size() && j < (int)B.size()) {
        if (A[i] < B[j]) res[k++] = A[i++];
        else res[k++] = B[j++];
    }
    while (i < (int)A.size()) res[k++] = A[i++];
    while (j < (int)B.size()) res[k++] = B[j++];
}

void build(int node, int l, int r) {
    if (l == r) {
        tree[node].assign(1, a[l]);
    } else {
        int mid = (l + r) >> 1;
        build(node << 1,     l,    mid);
        build(node << 1 | 1, mid+1, r);
        mergeVectors(tree[node<<1], tree[node<<1|1], tree[node]);
    }
}

int query(int node, int l, int r, int L, int R, int C) {
    if (r < L || R < l) {
        return 0;
    }
    if (L <= l && r <= R) {
        auto &v = tree[node];
        int pos = int(std::lower_bound(v.begin(), v.end(), C) - v.begin());
        return int(v.size()) - pos;
    }
    int mid = (l + r) >> 1;
    return query(node<<1, l, mid, L, R, C)
         + query(node<<1|1, mid+1, r, L, R, C);
}

int main(){
    tree.resize(4 * MAXN + 5);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    build(1, 0, N-1);
    while (Q--) {
        char op;
        cin >> op;
        if (op == 'A') {
            int L, R;
            int C;
            cin >> L >> R >> C;
            L--; R--;
            int ans = query(1, 0, N-1, L, R, C);
            cout << ans << "\n";
        } else {

        }
    }

    return 0;
}
